<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .hezi {
        position: absolute;
        width: 100px;
        height: 100px;
        background-color: blue;
        left: 0;
    }
</style>

<body>
    <button id="qidong">点击移动</button>
    <div class="hezi"></div>
    <script>
        var qidong = document.querySelector('#qidong');
        var hezi = document.querySelector('.hezi');
        qidong.addEventListener('click', function () {
            move(hezi, 1000);
        })
        function move(obj, target) {
            obj.timer = setInterval(function () {
                var speed = ((target - obj.offsetLeft) / 10);
                if (speed > 0) {
                    speed = Math.ceil((target - obj.offsetLeft) / 10);
                } else {
                    speed = Math.floor((target - obj.offsetLeft) / 10);
                }
                console.log((target - obj.offsetLeft));
                console.log((target - obj.offsetLeft) / 10);
                console.log(speed);
                console.log('   ');
                if (obj.offsetLeft == target) {
                    clearInterval(obj.timer);
                }
                obj.style.left = obj.offsetLeft + speed + 'px';
            }, 15)
        }
    </script>
</body>

</html>